//
//  NewAddFee.m
//  test
//
//  Created by 李彦宏 on 2018/3/8.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "NewAddFee.h"
#import "JWUserManager.h"
#import "JWGRUsermodel.h"

@interface NewAddFee ()<UITextViewDelegate>
@property (nonatomic, strong) JWGRUsermodel *model;
@property (weak, nonatomic) IBOutlet UIButton *SubmitBtn;//提交按钮
@property (weak, nonatomic) IBOutlet UITextView *FeeDescTeXView;//费用描述
@property (weak, nonatomic) IBOutlet UITextField *FeeSumNB;//费用合计



@end

@implementation NewAddFee

- (void)viewDidLoad {
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.model=[JWUserManager Gme];
    [super viewDidLoad];
    self.title=@"新增其他费用";
    [self setTextview];
    // Do any additional setup after loading the view from its nib.
}

-(void)setTextview{
    // 设置代理
    self.FeeDescTeXView.delegate = self;
    self.FeeDescTeXView.text=@"请输入其他费用描述！";
    // 设置文本字体
    self.FeeDescTeXView.font = [UIFont fontWithName:@"Arial" size:15];
    self.FeeDescTeXView.textColor=[UIColor lightGrayColor];
    // 设置文本对齐方式
    self.FeeDescTeXView.textAlignment = NSTextAlignmentLeft;
    //自动纠错
    self.FeeDescTeXView.autocorrectionType=UITextAutocorrectionTypeNo;
    //外框
    self.FeeDescTeXView.layer.borderColor=dominantColor.CGColor;
    self.FeeDescTeXView.layer.borderWidth=1;
    self.FeeDescTeXView.layer.cornerRadius=5;
    //不自动大小写
    self.FeeDescTeXView.autocapitalizationType=UITextAutocorrectionTypeNo;
    // 设置return键样式
    self.FeeDescTeXView.returnKeyType = UIReturnKeyDefault;
    // 设置是否可以拖动
    self.FeeDescTeXView.scrollEnabled = NO;
    
}
/**
 将要开始编辑
 @param textView textView
 @return BOOL
 */
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    return YES;
    
}
/**
 开始编辑
 @param textView textView
 */
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if ([self.FeeDescTeXView.text isEqualToString:@"请输入其他费用描述！"]) {
        
        self.FeeDescTeXView.text = @"";
        self.FeeDescTeXView.textColor=[UIColor blackColor];
    }
    
    
}
/**
 将要结束编辑
 
 @param textView textView
 
 @return BOOL
 */
- (BOOL)textViewShouldEndEditing:(UITextView *)textView
{
    
    return YES;
    
}

/**
 结束编辑
 
 @param textView textView
 */
-(void)textViewDidEndEditing:(UITextView *)textView
{
    if (self.FeeDescTeXView.text.length <1) {
        self.FeeDescTeXView.textColor=[UIColor lightGrayColor];
        self.FeeDescTeXView.text = @"请输入其他费用描述！";
    }
    
}
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if (textField == self.FeeSumNB){
        NSUInteger lengthOfString = string.length;
        for (NSInteger loopIndex = 0; loopIndex < lengthOfString; loopIndex++) {//只允许数字输入
            unichar character = [string characterAtIndex:loopIndex];
            if (character < 48) return NO; // 48 unichar for 0
            if (character > 57) return NO; // 57 unichar for 9
        }
        // Check for total length
        NSUInteger proposedNewLength = textField.text.length - range.length + string.length;
        if (proposedNewLength > 11) return NO;//限制长度
        return YES;
    }else{
        NSUInteger proposedNewLength = textField.text.length - range.length + string.length;
        if ( proposedNewLength > 20) return NO;//限制长度
        return YES;
    }
}


- (IBAction)SubmitAction:(id)sender {
//  NSLog(@"--Textview--%@", self.FeeDescTeXView.text);
//  NSLog(@"--Textfiled--%@", self.FeeSumNB.text);
    if(self.model.ID==nil){
        self.model.ID=self.model.gid;
    }
    NSDictionary *dict=@{
                         @"jwid" : JWid,
                         @"jwpassword" : JWpassword,
                         @"gid":self.model.ID,
                         @"discrabe":self.FeeDescTeXView.text,
                         @"money":self.FeeSumNB.text,
                         };
    [[AFNetworkTool shareManager]postJSONWithUrl:JWteacher_GRotherFee parmas:dict successData:^(id json) {
      //  NSLog(@"--json--%@", json);
        dispatch_async(dispatch_get_main_queue(), ^{
        [self.navigationController popViewControllerAnimated:YES];
            [MBProgressHUD showSuccess:@"提交成功！"];
        });
        
        
    } failure:^(NSError *error) {
        NSLog(@"--error--%@", error);
        [MBProgressHUD showError:@"提交失败！"];
    }];
   
        }


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
